import {message} from 'antd';
import {formatMessage} from './intl';

export const newOrUpdateValidator = data => {
    const requiredFields = [];
    if(!data || !data.brandId)
        requiredFields.push(
            formatMessage({
                id: 'validator.brandId',
                defaultMessage: '品牌'
            })
        );
    if(!data || !data.faultType)
        requiredFields.push(
            formatMessage({
                id: 'validator.faultType',
                defaultMessage: '故障类型'
            })
        );
    if(!data || !data.dutyUnitId)
        requiredFields.push(
            formatMessage({
                id: 'validator.dutyUnitId',
                defaultMessage: '责任单位'
            })
        );
    if(!data || !data.supplierId)
        requiredFields.push(
            formatMessage({
                id: 'validator.supplierId',
                defaultMessage: '供应商'
            })
        );
    if(requiredFields.length > 0) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.requied',
            defaultMessage: '必填'
        })}`);
        return false;
    }
    return true;
};
